/**
 * Created by seeker910 on 2014/8/21.
 * @description 组件名称命名约定：继承container组件，名称以ViewPart结尾;继承control组件，名称以Part结尾
 * 图片新闻：左侧图片轮播+右侧新闻列表
 */
Rsd.define('Rsd.hermit.sections.ImageNewsViewPart', {
    extend: 'Rsd.container.Component',
    requires: [
        'Rsd.hermit.sections.SlideImagePart',
        'Rsd.hermit.sections.ScrollListPart'
    ],
    xtype: 'image-news-view',
     /**
     * @description 标识该组件是否允许编辑
     */
    domEditable:true,
     /**
     * @description true:表示只允许在模板中修改
     */
    editInMaster:false,
    sizeUnit:'px',
    cls:'x-image-news-view',
    /*
    * [{src:'',formatString:'',text:''},{src:'',text:''}]
    * */
    dataSource:[],
    layout:'hbox',
    items:[
        {
            xtype:'slide-image',
            label:false,
            height:'100%',
            flex:7
        },
        {
            xtype:'scroll-list',
            title:'要 闻',
            margin:'0 0 0 2%',
            itemStyle:{
                overflow:'hidden',
                height:'45px',
                lineHeight:'45px',
                width:'100%',
                borderBottom: 'red 1px dotted'
            },
            cls:'list',
            itemClick:function(o,e){
                //console.log(o,e);
                window.open(o.data.url);
            },
            height:'100%',
            flex:3,
            autoScroll:true
        }
    ],
    /**
     * 
     * @param {*} config 
     */
    constructor: function ImageNewsViewPart(config) {
        config = config || {};
        this.apply(config);
        var me = this;

    },
    /**
     * 
     * @param {*} data 
     */
    loadData:function loadData(data) {
         
        this.dataSource = data||this.dataSource;
        
        var imgs =this.dataSource.map((p)=>{return  {

                label:false,
                width: '100%',
                height:'100%',
                dataSource:{ 
                    link:p.url,
                    image:p.src
                } 
            }
        });
        this.items[0].loadData (imgs);

        var news = this.dataSource.map((p)=>{return {
            label:false,
            width:'100%',
            height:'100%', 
            style: { lineHeight: '50px' },
            text:p.text,
            //url:p.url,
            data:p
        }});
        
        this.items[1].loadData(news);
    }


});